package cfgutil

import "time"

const (
	ConfigTypeIni = 1
)

var cfgType int

func Default(configType int) {
	cfgType = configType
	switch cfgType {
	case ConfigTypeIni:
		defaultIni()
	default:
		panic("unknown config type .")
	}
}

func Create(configType int, configFilePath string, fileName string) {
	cfgType = configType
	switch cfgType {
	case ConfigTypeIni:
		createIni(configFilePath, fileName)
	default:
		panic("unknown config type .")
	}
}

func Bind[T any](sectionName string) T {
	switch cfgType {
	case ConfigTypeIni:
		return bindIniToObj[T](sectionName)
	default:
		panic("unknown config type or config setting doesn't init .")
	}
}
func BindWithProfile[T any](profile string, sectionName string) T {
	switch cfgType {
	case ConfigTypeIni:
		return bindIniWithProfileToObj[T](profile, sectionName)
	default:
		panic("unknown config type or config setting doesn't init .")
	}
}

func BindToMap[T any](sectionName string) map[string]T {
	switch cfgType {
	case ConfigTypeIni:
		return bindIniToMap[T](sectionName)
	default:
		panic("unknown config type or config setting doesn't init .")
	}
}
func BindWithProfileToMap[T any](profile string, sectionName string) map[string]T {
	switch cfgType {
	case ConfigTypeIni:
		return bindIniWithProfileToMap[T](profile, sectionName)
	default:
		panic("unknown config type or config setting doesn't init .")
	}
}

func Section(name string) CfgSection {
	switch cfgType {
	case ConfigTypeIni:
		return iniSection(name)
	default:
		panic("unknown config type or config setting doesn't init .")
	}
}

func SectionWithProfile(profile string, name string) CfgSection {
	switch cfgType {
	case ConfigTypeIni:
		return iniSectionWithProfile(profile, name)
	default:
		panic("unknown config type or config setting doesn't init .")
	}
}

type CfgSection interface {
	String(name string) string
	Int(name string) int
	Float(name string) float64
	Bool(name string) bool
	Duration(name string) time.Duration
}
